package com.mlink.ai.chat.utils

import android.graphics.Rect
import android.view.View
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView

class LinearSpacingItemDecoration(
    private val spacing: Int,
    private val orientation: Int = LinearLayout.VERTICAL
) : RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        val position: Int = parent.getChildAdapterPosition(view) // item position
        if (orientation == LinearLayout.HORIZONTAL) {
            val itemCount = parent.adapter?.itemCount ?: 0
            if (position < itemCount - 1) {
                outRect.right = spacing // 设置 item 之间的间距
            }
        } else {
            outRect.bottom = spacing
        }
    }
}